package com.jch.mp.manner1.client;

import com.alibaba.fastjson.JSON;
import com.jch.mp.manner1.domain.message.ComplexMessage;
import com.jch.mp.manner1.domain.message.GroupMessage;
import com.jch.mp.manner1.domain.message.SimpleMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Manner1ClientHandler extends ChannelInboundHandlerAdapter {

    public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof SimpleMessage) {
            SimpleMessage simpleMessage = (SimpleMessage) msg;
            System.out.println(dateFormat.format(new Date()) + " 收到SimpleMessage: " + JSON.toJSONString(simpleMessage));
        } else if (msg instanceof GroupMessage) {
            GroupMessage groupMessage = (GroupMessage) msg;
            System.out.println(dateFormat.format(new Date()) + " 收到GroupMessage: " + JSON.toJSONString(groupMessage));
        } else if (msg instanceof ComplexMessage) {
            ComplexMessage complexMessage = (ComplexMessage) msg;
            System.out.println(dateFormat.format(new Date()) + " 收到ComplexMessage: " + JSON.toJSONString(complexMessage));
        }
    }
}
